package com.fenxiangtech.mall.manager;

import com.fenxiangtech.mall.dao.ImageDAO;
import com.fenxiangtech.mall.model.Image;
import com.fenxiangtech.mall.model.qc.ImageQC;
import com.fenxiangtech.mall.model.qc.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class ImageManager {

    @Autowired
    private ImageDAO imageDAO;

    public List<Image> queryImage(Image image, Integer pageIndex , Integer pageSize){
        Page page = new Page(pageIndex,pageSize);
        ImageQC qc  = new ImageQC();
        qc.setPage(page);
        BeanUtils.copyProperties(image,qc);
        List<Image> images = imageDAO.listImage(qc);
        return images;
    }

    public Long countImage(Image image){
        ImageQC qc  = new ImageQC();
        BeanUtils.copyProperties(image,qc);
        Long count = imageDAO.countImage(qc);
        return count;
    }

    public int saveImage(Image image){

        if(image.getId()!=null){
            return imageDAO.updateImage(image);
        }else {
            return imageDAO.insertImage(image);
        }

    }
    public int deleteImage(Long id){

        return imageDAO.deleteImageById(id);

    }



}
